<script type="text/javascript">
$(document).ready(function() {
    var initial_width;
    //初始化完成
    $('#rrserver_table').jqGrid({
        url: '/grid_rrserver',
        styleUI: 'Bootstrap',
        datatype: 'json',
        mtype: 'POST',
        colNames: ['编号', 'IP', '端口', '用户',
            "[['label owner'|translate]]", '[["label Creation time"|translate]]', '[["label operation"|translate]]'
        ],
        colModel: [{
            name: 'id',
            index: 'id',
            width: 6,
            align: '',
            hidden: true
        }, {
            name: 'address',
            index: 'address',
            width: 8,
            align: 'left',
            formatter:function(cell,option,row) {
                return '<a href="#" onclick="detail_open(\'' + option.gid + '\',\'' + option.rowId + '\')">' + cell + '</a>';
            },
            unformat: function(cell) {
                return cell;
            }
        }, {
            port: 'port',
            index: 'port',
            width: 8,
            align: 'left'
        }, {
            user: 'user',
            index: 'user',
            width: 8,
            align: 'left'
        }, {
            name: 'owner',
            index: 'owner',
            width: 6,
            align: 'left',
            hidden: true
        }, {
            name: 'created_at',
            index: 'created_at',
            width: 12,
            align: 'left'
        }, {
            name: 'service',
            index: 'service',
            width: 20,
            align: 'left',
            sortable: false,
	       detailHidden: true,
            formatter: function(cell, option, row) {
                var html = '';
                html += '<button title="编辑" class="btn btn-blue" onclick=confirm_rrserver_update(' + row[0] + ')>编辑</button>';
                html += '<button style="margin-left:10px;" title="删除" class="btn btn-blue" onclick=confirm_rrserver_delete(' + row[0] + ')>删除</button>';
                return html;
            }
        }, ],
        page: 1,
        rowNum: 10,
        sortname: 'id',
        sortorder: 'desc',
        viewrecords: true,
        multiselectWidth: 40,
        altclass: 'ui-priority-secondary',
        altRows: true,
        autowidth: true,
        shrinkToFit: true,
        gridComplete: function() {
            var gridData = $(this).jqGrid('getRowData');
            jqgrid_page($(this), gridData);
            jqgrid_resize($(this));
        },
        resizeStart: function() {
            initial_width = $(this).width();
        },
        resizeStop: function() {
            return;
        }
    });
});

function rrserver_delete(rrserver_id) {
    $.post("/rrserver_delete", {
            'id': rrserver_id
        },
        function(data) {
            console.log(data)
            if (data.reply.is_success) {
                $('#rrserver_table').trigger("reloadGrid");
                //                    SelfAlert("删除成功", "完成提示");
            } else {
                error = data.reply.error;
                SelfAlert("删除失败：" + error)
            }
        });
}

function confirm_rrserver_delete(rrserver_id) {
    msg = '确认删除?';
    SelfConfirm(msg, rrserver_delete, rrserver_id, "删除提示");
}

function confirm_rrserver_update(rrserver_id) {
    angular.element('#rrserver_controller').scope().open("/rrserver_update?id=" + rrserver_id);
}

$("#rrserver_create").click(function() {
    angular.element('#rrserver_controller').scope().open("/rrserver_create");
});
</script>
<div class="panel panel-f-style">
    <div class="panel-body">
        <div class="title-tag">
            <h3>站点</h3>
            <p>站点管理</p>
        </div>
        <div class="grid-tools">
            <div class="grid-operate pull-left">
                <button id="rrserver_controller" ng-controller="RRServerModalCtrl" ng-hide="true"></button>
                <button class="btn btn-blue" id="rrserver_create" type="button">[['button create'|translate]]</button>
            </div>
        </div>
        <div class="grid-body" id="div_rrserver_table">
            <table id="rrserver_table"></table>
        </div>
    </div>
</div>
